 import UsersApi from "../api/admins.js"

// 请求端口 浏览器端向服务端请求
export const request = ({ type = "GET", url, data = {},headers }) =>
    new Promise(resolve => {
        $.ajax({
            type,
            url,
            data,
            headers,
            success: resolve
        })
    })


export const ajaxInit = () => {
    // ajax设置
    $.ajaxSetup({
        // 调用ajax之前触发
        beforeSend(xhr) {
            // 获取令牌
            const token = UsersApi.getToken();
        
            // 如果有令牌修改请求头
            if (token) {
                xhr.setRequestHeader("authorization", `Bearer ${token}`);
            }
        }
    })
}
